package com.ruoyi.redtea.dualprevent.controller;


import com.ruoyi.common.core.domain.R;
import com.ruoyi.redtea.dualprevent.domain.entity.TrainAnalyseUnitRiskPoint;
import com.ruoyi.redtea.dualprevent.service.TrainAnalyseUnitRiskPointService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 分析单元（对象）的风险点(TrainAnalyseUnitRiskPoint)表控制层
 *
 * @author makejava
 * @since 2024-05-15 13:43:38
 */
@RestController
@RequestMapping("trainAnalyseUnitRiskPoint")
public class TrainAnalyseUnitRiskPointController {
    /**
     * 服务对象
     */
    @Resource
    private TrainAnalyseUnitRiskPointService trainAnalyseUnitRiskPointService;


    @GetMapping("list")
    public R<?> queryList(){
        return R.ok(trainAnalyseUnitRiskPointService.queryList());
    }

    /**
     * 新增数据
     *
     * @param trainAnalyseUnitRiskPoint 实体对象
     * @return 新增结果
     */
    @PostMapping
    public R<?> insert(@RequestBody TrainAnalyseUnitRiskPoint trainAnalyseUnitRiskPoint) {
        return R.ok(trainAnalyseUnitRiskPointService.insertRiskPoint(trainAnalyseUnitRiskPoint.getAnalyseUnitId(), trainAnalyseUnitRiskPoint.getRiskPointName()));
    }

    /**
     * 修改数据
     *
     * @param trainAnalyseUnitRiskPoint 实体对象
     * @return 修改结果
     */
    @PutMapping
    public R<?> update(@RequestBody TrainAnalyseUnitRiskPoint trainAnalyseUnitRiskPoint) {
        return R.ok(this.trainAnalyseUnitRiskPointService.updateRiskPoint(trainAnalyseUnitRiskPoint.getId(),trainAnalyseUnitRiskPoint.getRiskPointName()));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @DeleteMapping
    public R<?> delete(@RequestParam("id") Long id) {
        return R.ok(this.trainAnalyseUnitRiskPointService.delRiskPoint(Math.toIntExact(id)));
    }
}

